<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <title>详情-添加币资产</title>

    <style type="text/css">
        body,
        html {
            overflow-x: hidden;
            background-color: #f5f5f5 !important;
        }

        header {
            color: #FFFFFF;
            background: -webkit-linear-gradient(left top, #0F9BEB, #1569C8);
            /* Safari 5.1 - 6.0 */
            background: -o-linear-gradient(bottom right, #0F9BEB, #1569C8);
            /* Opera 11.1 - 12.0 */
            background: -moz-linear-gradient(bottom right, #0F9BEB, #1569C8);
            /* Firefox 3.6 - 15 */
            background: linear-gradient(to bottom right, #0F9BEB, #1569C8);
            background: -webkit-linear-gradient(left top, #0F9BEB, #1569C8);
            /* 标准的语法*/
            box-shadow: 0 0px 7px #0c5ebb;
        }

        .aui-bar-nav {
            top: 0;
            line-height: 2.25rem;
            background-color: #03a9f4;
            color: #ffffff;
            padding: 15px 0 2px 0;
        }

        .more-p {
            height: 2.25rem;
            font-size: 0.7rem;
            padding-left: 15px;
            color: #999999;
            line-height: 45px;
        }

        .aui-list-item-right {
            color: #000000 !important;
        }

        .aui-list-item {
            height: 2.7rem !important;
            line-height: 2.7rem;
            margin-left: 0 !important;
            border-bottom: 0.1rem solid #EEEEEE !important;
        }

        .aui-list.aui-list-in .aui-list-item {
            background-image: none !important;
        }

        #buyPrice,
        #saveTo {
            border-bottom: 0rem solid #FFFFFF !important;
        }

        .buyBtns,
        .saveBtns {
            margin-right: 0.75rem;
        }

        .saveBtns button:first-child {
            background-color: #1569c8;
            color: #FFFFFF;
        }

        .saveBtns button:last-child {
            background-color: #EEEEEE;
            color: #999999;
        }

        #perPrice {
            background-color: #1569c8;
            color: #FFFFFF;
        }

        #sumPrice {
            background-color: #EEEEEE;
            color: #999999;
        }

        button {
            margin: 0 0.25rem;
            font-size: 0.6rem;
            width: 3rem;
            height: 1.2rem;
            line-height: 1.35rem;
            color: #fff;
        }

        #buyPrice,
        #saveTo {
            height: 2.75rem;
            line-height: 3.3rem;
        }

        .aui-btn-block {
            color: #ffffff;
            height: 2rem;
            line-height: 2rem;
            background: -webkit-linear-gradient(left top, #0F9BEB, #1569C8);
            /* Safari 5.1 - 6.0 */
            background: -o-linear-gradient(bottom right, #0F9BEB, #1569C8);
            /* Opera 11.1 - 12.0 */
            background: -moz-linear-gradient(bottom right, #0F9BEB, #1569C8);
            /* Firefox 3.6 - 15 */
            background: linear-gradient(to bottom right, #0F9BEB, #1569C8);
            background: -webkit-linear-gradient(left top, #0F9BEB, #1569C8);
            /* 标准的语法*/
            box-shadow: 0 0px 4px #0c5ebb;
        }

        .aui-btn-block-on {
            color: #ffffff !important;
            height: 2rem;
            line-height: 2rem;
            background-color: #cecece !important;
            width: 100%;
        }

        #walletIpt,
        #toBuyprice {
            height: 1.7rem !important;
            line-height: 1.7rem !important;
        }

        #walletIpt div,
        #priceIpt div {
            color: #999999 !important;
            font-size: 0.6rem !important;
            color: #999999 !important;
            font-size: 0.6rem !important;
        }

        #addExch {
            color: #999999 !important;
            font-size: 0.6rem !important;
            height: 2.2rem;
            line-height: 2.2rem;
        }

        .aui-content-padded {
            margin-top: 1.1rem !important;
        }

        .aui-list .aui-list-in .aui-margin-b-15 {
            box-shadow: 0.1rem 0 #EEEEEE;
        }

        span#tokenIpt, span#sumIpt {
            font-size: 0.6rem;
            color: #999999;
            text-align: right;
            margin-right: 0.75rem;
        }

        span#priceIpt {
            color: #999999 !important;
            font-size: 0.6rem !important;
        }

        span#unit {
            color: #999999 !important;
            font-size: 0.6rem !important;
        }

        .aui-list-item-title.aui-list-item-arrow {
            width: 100%;
        }

        input.inputAdr {
            color: #999999 !important;
            font-size: 0.6rem !important;
        }
    </style>

</head>

<body>
<header class="aui-bar aui-bar-nav">
    <div class="aui-pull-left aui-btn" onclick="back()">
        <span class="aui-iconfont aui-icon-left"></span>
    </div>
    <div class="aui-title">添加币资产</div>

    <!--<div class="aui-info-item sc-item"><img src="../../image/btn/nav_sz_1@2x.png" /></div>-->
</header>
<section class="aui-content">
    <p class=" more-p"> Token信息</p>
    <ul class="aui-list aui-list-in aui-margin-b-15">

        <li class="aui-list-item" onclick="toAddToken()">
            <a class="aui-list-item-inner aui-list-item-arrow">
                <span class="aui-list-item-title">添加token</span>
                <span id="tokenIpt"></span>
            </a>
        </li>
        <li class="aui-list-item" onclick="toHolderSum()">
            <a class="aui-list-item-inner aui-list-item-arrow">
                <span class="aui-list-item-title">持有数量</span>
                <span id="sumIpt"></span>
            </a>
        </li>
        <li class="aui-list-item " id="buyPrice">
            <div class="">买入价格</div>
            <div class="buyBtns">
                <button id="perPrice">单价</button>
                <button id="sumPrice">总价</button>
            </div>
        </li>
        <li class="aui-list-item" onclick="toBuyPrice()">
            <a class="aui-list-item-arrow">
                <div class="aui-list-item-title"><span id="priceIpt">请输入价格</span></div>

            </a>
        </li>
        <li class="aui-list-item " id="saveTo">
            <div class="aui-list-item-sumIpttitle">存放于</div>
            <div class="saveBtns">
                <button id="saveWalet">钱包</button>
                <button id="saveExch">交易所</button>
            </div>
        </li>
        <li class="aui-list-item " id="walletIpt">
            <input class="inputAdr" type="text" name="" id="" value="" placeholder="请输入钱包地址" autofocus="autofocus"/>
            <!--<div class="aui-list-item-title">请输入钱包地址</div> aui-list-item-arrow-->
        </li>

    </ul>

    <div class="aui-content-padded">
        <button id="add" class="aui-btn aui-btn-block-on" tapmode onclick="addBizichan()">添加</button>
    </div>
</section>

</body>
<script src="../../script/api.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="../../script/aui-sharebox.js"></script>
<script src="../../jquery-2.1.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../script/tool.js"></script>
<script type="text/javascript">
  var moneyType = 1;
  var address = 1;
  var bi = {
    tokenName: "",
    AbbreviationName: "",
    number: 0,
    money: 0,
    moneyType: 1,
    address: 1
  }

  function judge() {
    moneyType = sessionStorage.getItem('moneyType1') || 1
    //单价还是总价
    bi.moneyType = sessionStorage.getItem('moneyType') || 1;
    //币名
    bi.tokenName = sessionStorage.getItem('tokenName') || "";
    //币的简写
    bi.AbbreviationName = sessionStorage.getItem('AbbreviationName') || "";
    //填写的买入价格
    bi.money = sessionStorage.getItem('priceIptArr') || 0;
    //数量
    bi.number = sessionStorage.getItem('sum') || 0;
    //数量
    bi.address = sessionStorage.getItem('address') || 1;

    if (bi.tokenName != "") {
      $("#tokenIpt").html(bi.tokenName + "(" + bi.AbbreviationName + ")");
    }
    if (parseInt(bi.number) > 0) {
      $("#sumIpt").html(bi.number)
    }

    if (parseInt(bi.money) > 0) {
      if (bi.moneyType == 1) {
        if (moneyType == 1) {
          console.log("1")
          $("#priceIpt").html(bi.money + "CNY")
        } else {
          console.log("2")
          $("#priceIpt").html(bi.money * (bi.number == 0 ? 1 : bi.number) + "CNY")
        }
      } else {
        if (moneyType == 1) {
          console.log("3")
          $("#priceIpt").html(bi.money / (bi.number == 0 ? 1 : bi.number) + "CNY")
        } else {
          console.log("4")
          $("#priceIpt").html(bi.money + "CNY")
        }
      }
    }

    $("#perPrice").css({
      "background": "#eeeeee",
      "color": "#999999"
    })
    $("#sumPrice").css({
      "background": "#eeeeee",
      "color": "#999999"
    })
    $("#saveWalet").css({
      "background": "#eeeeee",
      "color": "#999999"
    })
    $("#saveExch").css({
      "background": "#eeeeee",
      "color": "#999999"
    })

    if (moneyType == 1) {
      $("#perPrice").css({
        "background": "#1569c8",
        "color": "#ffffff"
      })
    } else {
      $("#sumPrice").css({
        "background": "#1569c8",
        "color": "#ffffff"
      })
    }

    if (bi.address == 1) {
      $("#saveWalet").css({
        "background": "#1569c8",
        "color": "#ffffff"
      })
    } else {
      $("#saveExch").css({
        "background": "#1569c8",
        "color": "#ffffff"
      })
    }

    if (bi.tokenName == "") {
      isButton(false);
      return
    }

    if (parseInt(bi.number) <= 0) {
      isButton(false);
      return
    }

    if (parseInt(bi.money) <= 0) {
      isButton(false);
      return
    }
    console.log(JSON.stringify(bi))

    isButton(true);
  }

  judge()

  function isButton(is) {
    if (is) {
      $("#add").attr("disabled", false);
      $("#add").addClass("aui-btn-block");
      $("#add").removeClass("aui-btn-block-on");
    } else {
      $("#add").attr("disabled", true);
      $("#add").addClass("aui-btn-block-on");
      $("#add").removeClass("aui-btn-block");
    }
  }

  function toAddToken() {
    window.location.href = "../search/search-addtoken.html"
  }

  function toHolderSum() {
    window.location.href = "detail-chiyou.html"
  }

  function toBuyPrice() {
    sessionStorage.setItem('moneyType', moneyType)
    window.location.href = "detail-mairu.html"
  }

  function toSaved() {
    window.location.href = "../search/search-addexchange.html"
  }

  //切换时计算总价加入，背景、字体切换
  //单价
  $("#perPrice").click(function () {
    $(this).css({
      "background": "#1569c8",
      "color": "#ffffff"
    });
    $("#sumPrice").css({
      "background": "#eeeeee",
      "color": "#999999"
    });
    sessionStorage.setItem('moneyType1', 1)
    moneyType = 1;
    judge();
  })
  //总价
  $("#sumPrice").click(function () {
    $(this).css({
      "background": "#1569c8",
      "color": "#ffffff"
    });
    $("#perPrice").css({
      "background": "#eeeeee",
      "color": "#999999"
    });
    sessionStorage.setItem('moneyType1', 2)
    moneyType = 2;
    judge();
  })

  // 存到钱包
  $("#saveWalet").click(function () {
    $(this).css({
      "background": "#1569c8",
      "color": "#ffffff"
    });
    $("#saveExch").css({
      "background": "#eeeeee",
      "color": "#999999"
    });
    sessionStorage.setItem('address', 1)
    bi.address = 1;
    $("#walletIpt").empty();
    $("#walletIpt").append('<input class="inputAdr" type="text" name="" id="" value="" placeholder="请输入钱包地址" autofocus="autofocus"/>')
  })

  // 存储交易所地址
  $("#saveExch").click(function () {
    $(this).css({
      "background": "#1569c8",
      "color": "#ffffff"
    });
    $("#saveWalet").css({
      "background": "#eeeeee",
      "color": "#999999"
    });
    sessionStorage.setItem('address', 2)
    bi.address = 2;
    $("#walletIpt").empty();
    $("#walletIpt").append('<div class="aui-list-item-title aui-list-item-arrow" id="addExch" onclick="toSaved()">前往添加交易所</div>');
  })

  function addBizichan() {
    var bizhichanList = JSON.parse(localStorage.getItem('bizhichanList')) || [];

//    console.log(typeof bizhichanList)

    bizhichanList.push(bi)
    localStorage.setItem('bizhichanList', JSON.stringify(bizhichanList));
    init();
    window.location.href = "detail-bizichan.html"
  }

  function back() {
    init();
    backBefore();
  }

  function init() {
    localStorage.setItem('tokenName', "");
    localStorage.setItem('AbbreviationName', "");
    localStorage.setItem('priceIptArr', 0);
    localStorage.setItem('sum', 0);
    localStorage.setItem('moneyType', 1);
  }

</script>

</html>
